/**
 * <p><b>Title:</b> SyncTaskController.java </p>
 * @Package com.wondertek.oes.charge.service.controller
 */

package com.wondertek.poms.service.controller;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

import com.wondertek.poms.common.constant.Constants;
import com.wondertek.poms.common.controller.BaseController;
import com.wondertek.poms.common.exception.MessageCodes;
import com.wondertek.poms.common.utils.validate.ValidateFilter;
import com.wondertek.poms.common.vo.PageBean;
import com.wondertek.poms.common.vo.ResultBean;
import com.wondertek.poms.core.service.ISyncTaskService;
import com.wondertek.poms.dao.po.SyncTask;
import com.wondertek.poms.service.vo.SyncTaskVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;

import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.context.annotation.Scope;



import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;



/**
 * <p><b>SyncTaskController Description:</b>  Controller层实现</p>
 * @author 窦再兴
 * <p><b>DATE</b> 2020-10-21 13:50:43</p>
 */

@Api(" ")
@RestController
@Scope("prototype")
@RequestMapping(value="/sync-task")
public class SyncTaskController extends BaseController {

	@Autowired
	private ISyncTaskService syncTaskService;

	@ApiOperation(" 列表")
	@GetMapping("/list")
	@ResponseBody
	public ResultBean list(HttpServletRequest request,
						   SyncTaskVo syncTaskVo,
						   @RequestParam(defaultValue = "1") int page,
						   @RequestParam(defaultValue = "20") int rows,
						   @RequestParam(defaultValue = "SYNC_TIME") String sidx,
						   @RequestParam(defaultValue = "desc") String sord) {
		SyncTask syncTask = new SyncTask();
		BeanUtils.copyProperties(syncTaskVo, syncTask);

		Page<SyncTask> pages = syncTaskService
				.findAll(syncTask, page, rows, sord, sidx);

		return PageBean.ok(pages.getTotalPages(), pages.getTotalElements(), pages.getContent());
	}


}
	/**

	@ApiOperation(" 新增")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id", required = true),
		@ApiImplicitParam(name = "accessId", required = true),
		@ApiImplicitParam(name = "accessPlatformId", required = true),
		@ApiImplicitParam(name = "accessPlatformType", required = true),
		@ApiImplicitParam(name = "accessPwd", required = true),
		@ApiImplicitParam(name = "accessSeq", required = true),
		@ApiImplicitParam(name = "accesstime", required = true),
		@ApiImplicitParam(name = "actiontype", required = true),
		@ApiImplicitParam(name = "basePath", required = true),
		@ApiImplicitParam(name = "contentId", required = true),
		@ApiImplicitParam(name = "cpId", required = true),
		@ApiImplicitParam(name = "distResult", required = true),
		@ApiImplicitParam(name = "endtime", required = true),
		@ApiImplicitParam(name = "failReason", required = true),
		@ApiImplicitParam(name = "fileIds", required = true),
		@ApiImplicitParam(name = "needBc", required = true),
		@ApiImplicitParam(name = "notifytype", required = true),
		@ApiImplicitParam(name = "offlineStatus", required = true),
		@ApiImplicitParam(name = "oprCode", required = true),
		@ApiImplicitParam(name = "oprTime", required = true),
		@ApiImplicitParam(name = "priority", required = true),
		@ApiImplicitParam(name = "remoteip", required = true),
		@ApiImplicitParam(name = "respTime", required = true),
		@ApiImplicitParam(name = "resultCode", required = true),
		@ApiImplicitParam(name = "resultdesc", required = true),
		@ApiImplicitParam(name = "servType", required = true),
		@ApiImplicitParam(name = "starttime", required = true),
		@ApiImplicitParam(name = "status", required = true),
		@ApiImplicitParam(name = "syncMode", required = true),
		@ApiImplicitParam(name = "syncTime", required = true),
		@ApiImplicitParam(name = "updateFields", required = true),
		@ApiImplicitParam(name = "version", required = true),
	})
	@PostMapping(value = "/add")
	@ResponseBody
	//TODO (需要删除不需要的属性列)
	public ResultBean add(HttpServletRequest request, SyncTaskVo syncTaskVo) {
		List<String> messageList = ValidateFilter.getFilterMessage(syncTaskVo, Constants.VALIDATE_DEFAULT);
		if (!messageList.isEmpty()) {
			return ResultBean.error(messageList.toString());
		}
		
		if (isRepeat(syncTaskVo)) 
			return ResultBean.error(MessageCodes.get(MessageCodes.M980600));
	
		SyncTask syncTask = new SyncTask();
		BeanUtils.copyProperties(syncTaskVo, syncTask);

		syncTaskService.save(syncTask);
		return ResultBean.ok(syncTask);
	}
	
	*/
/**
	 * <p><b>Title:</b> isRepeat</p>
	 * <p><b>Description:</b> 判断 名称是否重复</p>
	 * @author douzi
	 * @param syncTaskVo
	 *//*

	private boolean isRepeat(SyncTaskVo syncTaskVo) {
		*/
/*SyncTask temp = new SyncTask();
		temp.setChannelName(syncTaskVo.getName());
		Optional<SyncTask> syncTaskOpt = syncTaskService.findOne(Example.of(temp));
		if (syncTaskOpt.isPresent()) {
			SyncTask syncTask = syncTaskOpt.get();
			if (syncTaskVo.getId() != null && syncTaskVo.getId() != syncTask.getId())
				return true;
			else if (syncTaskVo.getId() == null)
				return true;
		}*//*

		return false;
	}
	
	@ApiOperation(" 详情")
	@ApiImplicitParam(name = "id", required = true, paramType = "query", dataType = "Long")
	@GetMapping(value = "/get")
	@ResponseBody
	public ResultBean get(Long id) {
		SyncTask syncTask = syncTaskService.get(id);
		return ResultBean.ok(syncTask);
	}
	
	@ApiOperation(" 变更")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id", required = true),
		@ApiImplicitParam(name = "accessId", required = true),
		@ApiImplicitParam(name = "accessPlatformId", required = true),
		@ApiImplicitParam(name = "accessPlatformType", required = true),
		@ApiImplicitParam(name = "accessPwd", required = true),
		@ApiImplicitParam(name = "accessSeq", required = true),
		@ApiImplicitParam(name = "accesstime", required = true),
		@ApiImplicitParam(name = "actiontype", required = true),
		@ApiImplicitParam(name = "basePath", required = true),
		@ApiImplicitParam(name = "contentId", required = true),
		@ApiImplicitParam(name = "cpId", required = true),
		@ApiImplicitParam(name = "distResult", required = true),
		@ApiImplicitParam(name = "endtime", required = true),
		@ApiImplicitParam(name = "failReason", required = true),
		@ApiImplicitParam(name = "fileIds", required = true),
		@ApiImplicitParam(name = "needBc", required = true),
		@ApiImplicitParam(name = "notifytype", required = true),
		@ApiImplicitParam(name = "offlineStatus", required = true),
		@ApiImplicitParam(name = "oprCode", required = true),
		@ApiImplicitParam(name = "oprTime", required = true),
		@ApiImplicitParam(name = "priority", required = true),
		@ApiImplicitParam(name = "remoteip", required = true),
		@ApiImplicitParam(name = "respTime", required = true),
		@ApiImplicitParam(name = "resultCode", required = true),
		@ApiImplicitParam(name = "resultdesc", required = true),
		@ApiImplicitParam(name = "servType", required = true),
		@ApiImplicitParam(name = "starttime", required = true),
		@ApiImplicitParam(name = "status", required = true),
		@ApiImplicitParam(name = "syncMode", required = true),
		@ApiImplicitParam(name = "syncTime", required = true),
		@ApiImplicitParam(name = "updateFields", required = true),
		@ApiImplicitParam(name = "version", required = true),
	})
	@PutMapping(value = "/edit")
	@ResponseBody
	//TODO (需要删除不需要的属性列)
	public ResultBean update(HttpServletRequest request, SyncTaskVo syncTaskVo) {
		List<String> messageList = ValidateFilter.getFilterMessage(syncTaskVo, Constants.VALIDATE_UPDATE);
		if (!messageList.isEmpty()) {
			return ResultBean.error(messageList.toString());
		}
		
		if (isRepeat(syncTaskVo)) 
			return ResultBean.error(MessageCodes.get(MessageCodes.M980600));
		
		SyncTask syncTask = new SyncTask();
		BeanUtils.copyProperties(syncTaskVo, syncTask);
		return ResultBean.ok(syncTaskService.merge(syncTask));
	}
	
	@ApiOperation(" 删除")
	@ApiImplicitParam(name = "id", required = true, paramType = "query", dataType = "Long")
	@DeleteMapping(value = "/del")
	@ResponseBody
	public ResultBean delete(Long id) {
		syncTaskService.deleteById(id);
		return ResultBean.ok();
	}
}
*/
